package com.yimixian.app.ui;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ta.utdid2.android.utils.StringUtils;
import com.yimixian.app.model.CartUpdateDescription;

import java.util.List;

/**
 * Created by zhilian-2 on 2016/3/1.
 */
public class AutoMoreTextLinearlayout extends LinearLayout{
    public AutoMoreTextLinearlayout(Context context) {
        super(context);
    }

    public AutoMoreTextLinearlayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AutoMoreTextLinearlayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setInitData(List<CartUpdateDescription> mList, String defaultColor, int defaultSize,String symbol,int index){
        removeAllViews();
        if (mList == null) return;
        for (int i = 0; i < mList.size(); i++){
            CartUpdateDescription mCartUpdateDescription = mList.get(i);
            if (mCartUpdateDescription == null) return;
            String textColor = StringUtils.isEmpty(mCartUpdateDescription.color) ? defaultColor :
                    mCartUpdateDescription.color;
            if (textColor.charAt(0)  != '#') textColor = "#" + textColor;
            int textSize = mCartUpdateDescription.fontsize == 0 ? defaultSize : mCartUpdateDescription.fontsize;
            TextView textView = new TextView(getContext());
            textView.setTextSize(textSize);
            textView.setTextColor(Color.parseColor(textColor));
            if(index!=-1&&i==index&&symbol!=null){
                textView.setText(StringUtils.isEmpty(mCartUpdateDescription.content) ? "" :
                    symbol+mCartUpdateDescription.content);
            }else{
                textView.setText(StringUtils.isEmpty(mCartUpdateDescription.content) ? "" :
                    mCartUpdateDescription.content);
            }
            this.addView(textView);
        }
    }
    public void setInitData(List<CartUpdateDescription> mList, String defaultColor, int defaultSize){
        setInitData(mList,defaultColor,defaultSize,null,-1);
    }
}
